/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package homework1;

import java.util.Random;

/**
 *
 * @author User
 */
public class Homework1 {

    public static int[] shakeSort(int[] arr) {
        boolean t = true;
        int leftInd = 0;
        int rightInd = arr.length - 2;
        int shift = 1;
        while (t) {
            t = false;
            for (int i = leftInd; i != rightInd + shift; i += shift) {
                if (arr[i] > arr[i + 1]) {
                    int e = arr[i + 1];
                    arr[i + 1] = arr[i];
                    arr[i] = e;
                    t = true;
                }
            }
            int e = leftInd;
            leftInd = rightInd;
            rightInd = e;
            shift = -shift;
        }
        return arr;
    }
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        
        Random rand = new Random();
        int[] arr;
        arr = new int[1000];
        for(int j=0 ; j<=999;j++){
            arr[j] = Math.abs(rand.nextInt());
        }
        long t1 =  System.currentTimeMillis();
        shakeSort(arr);
        long t2 = System.currentTimeMillis();
        System.out.println("время сортировки "+(t2-t1));
        System.out.println("сложность О(n^2)");
        System.out.println("-----------------------------");
         for(int j=0 ; j<=999;j++){
             System.out.println(arr[j]);
        }
        
    }
}

